package com.studentstreet.tools;

import java.text.Collator;
import java.text.RuleBasedCollator;
import java.util.Comparator;

import com.studentstreet.entities.GoodsEntity;

public class SortByName implements Comparator {

	@Override
	public int compare(Object lhs, Object rhs) {
		GoodsEntity goods1 = (GoodsEntity) lhs;
		GoodsEntity goods2 = (GoodsEntity) rhs;
		// 按中文拼音排序
		RuleBasedCollator collator = (RuleBasedCollator) Collator
				.getInstance(java.util.Locale.CHINA);
		return collator.compare(goods1.getName(), goods2.getName());
		// return
		// goods1.getName().compareTo(goods2.getName());此方法不能按拼音排序，而是按Unicode排序
	}

}
